package com.billow.touch
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TouchEvent;
	import flash.geom.Rectangle;
	import flash.ui.Multitouch;
	import flash.utils.getTimer;

	public class TouchControl
	{
		private static var _localX:Number;
		private static var _localY:Number;
		private static var _stageX:Number;
		private static var _stageY:Number;
		private static var _sizeX:Number;
		private static var _sizeY:Number;
		private static var _pressure:Number;
		private static var _timestamp:Number;
		private static var _touchPointID:int;
		
		
		/** 设置事件目标，格式化数据 */
		public static function set event(event:Event):void
		{
			_localX = event["localX"];
			_localY = event["localY"];
			_stageX = event["stageX"];
			_stageY = event["stageY"];
			
			if(event is TouchEvent)
			{
				_touchPointID = event["touchPointID"];
				_pressure = event["pressure"];
				_sizeX = event["sizeX"];
				_sizeY = event["sizeY"];
				_timestamp = event["timestamp"];
			}else{
				_touchPointID = 0;
				_pressure = 0;
				_sizeX = 0;
				_sizeY = 0;
				_timestamp = getTimer();
			}
		}
		
		
		
		/** 事件发生点相对于所属 Sprite 的水平坐标 */
		public static function get localX():Number{return _localX;}
		/** 事件发生点相对于所属 Sprite 的垂直坐标 */
		public static function get localY():Number{return _localY;}
		/** 事件发生点在全局舞台坐标中的水平坐标 */
		public static function get stageX():Number{return _stageX;}
		/** 事件发生点在全局舞台坐标中的垂直坐标 */
		public static function get stageY():Number{return _stageY;}
		/** 接触区域的宽度 */
		public static function get sizeX():Number{return _sizeX;}
		/** 接触区域的高度 */
		public static function get sizeY():Number{return _sizeY;}
		/** 0.0 和 1.0 之间的值表示强制接触设备。如果设备不支持检测压力，则此值为 1.0 */
		public static function get pressure():Number{return _pressure;}
		/** 相对于应用程序开始的事件时间戳（毫秒） */
		public static function get timestamp():Number{return _timestamp;}
		/** 分配给触摸点的唯一标识号（作为 int） */
		public static function get touchPointID():int{return _touchPointID;}
		
		
		
		
		
		
		
		/** 开始拖动 */
		public static function startTouchDrag(target:Sprite ,touchPointID:int, lockCenter:Boolean=false, bounds:Rectangle=null):void
		{
			if(Multitouch.supportsTouchEvents == false)
			{
				target.startDrag(lockCenter ,bounds);
			}else{
				target.startTouchDrag(touchPointID ,lockCenter ,bounds);
			}
		}
		
		/** 停止拖动 */
		public static function stopTouchDrag(target:Sprite ,touchPointID:int):void
		{
			if(Multitouch.supportsTouchEvents == false)
			{
				target.stopDrag();
			}else{
				target.stopTouchDrag(touchPointID);
			}
		}
		
		
		
		
		
		
		/** 按下 */
		public static function get TOUCH_BEGIN():String
		{
			return Multitouch.supportsTouchEvents?TouchEvent.TOUCH_BEGIN:MouseEvent.MOUSE_DOWN;
		}
		
		/** 松开 */
		public static function get TOUCH_END():String
		{
			return Multitouch.supportsTouchEvents?TouchEvent.TOUCH_END:MouseEvent.MOUSE_UP;
		}
		
		/** 移动 */
		public static function get TOUCH_MOVE():String
		{
			return Multitouch.supportsTouchEvents?TouchEvent.TOUCH_MOVE:MouseEvent.MOUSE_MOVE;
		}
		
		/** 移出 */
		public static function get TOUCH_OUT():String
		{
			return Multitouch.supportsTouchEvents?TouchEvent.TOUCH_OUT:MouseEvent.MOUSE_OUT;
		}
		
		/** 移入 */
		public static function get TOUCH_OVER():String
		{
			return Multitouch.supportsTouchEvents?TouchEvent.TOUCH_OVER:MouseEvent.MOUSE_OVER;
		}
		
		/** roll 移出 */
		public static function get TOUCH_ROLL_OUT():String
		{
			return Multitouch.supportsTouchEvents?TouchEvent.TOUCH_ROLL_OUT:MouseEvent.ROLL_OUT;
		}
		
		/** roll 移入 */
		public static function get TOUCH_ROLL_OVER():String
		{
			return Multitouch.supportsTouchEvents?TouchEvent.TOUCH_ROLL_OVER:MouseEvent.ROLL_OVER;
		}
		
		/** 点击 */
		public static function get TOUCH_TAP():String
		{
			return Multitouch.supportsTouchEvents?TouchEvent.TOUCH_TAP:MouseEvent.CLICK;
		}
	}
}